<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<div id="app"></div>
<!--引入react核心库-->
<script src="../React-js/react.development.js"></script>
<!--引入reac-dom 用于支持react操作dom-->
<script src="../React-js/react-dom.development.js"></script>
<!--显示props数据类型显示-->
<script src="../React-js/prop-types.js"></script>

<!--引入babel 用于讲jsx语法转js语法-->
<script src="../React-js/babel.min.js"></script>
<script type="text/babel">

    class LolInput extends React.Component {
        input_1 = React.createRef() //接受dom
        input_2 = React.createRef()//接收dom
        state = {
            isHot: true
        }


        render() {
            return <div>
                <div>问题描述：每次更新节点，函数式ref，第一次执行，会传来null</div>
                <input ref={this.input_1} placeholder="请输入"/>
                <button onClick={() => this.showVal('input_1')}>弹出内容</button>
                <input ref={this.input_2} onBlur={() => this.showVal('input_2')}
                       placeholder="失去焦点，自动弹出内容"/>
                <div>
                    今天{this.state.isHot ? '热' : '冷'}
                    <button onClick={this.editWeather}>切换天气</button>
                </div>
            </div>
        }

        editWeather = () => {
            this.setState({
                isHot: !this.state.isHot
            })
        }

        showVal = (field) => {
            const dom = this[field]
            alert(dom.current.value)

        }


    }


    ReactDOM.render(<LolInput/>, document.getElementById('app'))
</script>
</body>
</html>